package com.example.lianxi;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {
    private Button bt1;
    private Button bt2;
    private ImageView iv;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    private void initView() {
        bt1 = (Button) findViewById(R.id.bt1);
        bt1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(MainActivity.this, Main2Activity.class));
                overridePendingTransition(R.anim.screen_animation, R.anim.screen_animation_out);

            }
        });
        bt2 = (Button) findViewById(R.id.bt2);
        bt2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {     //组合动画
                ObjectAnimator translationX = ObjectAnimator.ofFloat(iv, "translationX", 0, 200);
                ObjectAnimator translationY = ObjectAnimator.ofFloat(iv, "translationY", 0, 300, 0, 300);
                AnimatorSet animatorSet = new AnimatorSet();
                animatorSet.play(translationY).with(translationX);
                animatorSet.start();
            }
        });
        iv = (ImageView) findViewById(R.id.iv);
    }
}
